// pages/regimental-commander/refund-handle/refund-handle.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    receivingStatusName: '',
    receivingStatusValue: '',
    receivingStatusShow: false,
    receivingStatusList: [
      { name: '司机未到自提点', value: 1 },
      { name: '司机送达，该商品没货', value: 2 },
      { name: '货物在自提点，顾客未提货', value: 3 },
      { name: '顾客已提货', value: 4 },
      { name: '顾客已退货到自提点', value: 5 }
    ],
    examineValue: '',
    remark: '',
    btn: null
  },

  /**
   * 收货状态选中
   * @param {Object} e 
   */
  receivingStatusSelected: function(e) {
    const { item } = e.currentTarget.dataset.item
    this.setData({
      receivingStatusName: item.name,
      receivingStatusValue: item.value,
      receivingStatusShow: false
    })
  },
  
  radioItemClick: function(e) {
    this.onExamineChange({detail: e.currentTarget.dataset.name})
  },
  /**
   * 
   * @param {Object} e 
   */
  onExamineChange: function(e) {
    const value = e.detail
    this.setData({
      examineValue: value
    })
  },

  /**
   * 显示动作面板
   * @param {Object} e 
   */
  showActionSheet: function(e) {
    const type = e.currentTarget.dataset.sheetType
    this.setData({
      [type]: true
    })
  },

  /**
   * 隐藏动作面板
   * @param {Object} e 
   */
  hideActionSheet: function(e) {
    const type = e.currentTarget.dataset.sheetType
    this.setData({
      [type]: false
    })
  },

  /**
   * 提交数据
   */
  submitRefundHandle: function() {
    const { receivingStatusValue, examineValue, remark, btn } = this.data
    if (!receivingStatusValue) {
      wx.showToast({
        icon: 'none',
        title: '请选择收货状态',
      })
      return
    }
    if (!examineValue) {
      wx.showToast({
        icon: 'none',
        title: '请选择是否属实',
      })
      return
    }
    const params = {
      order_refund_id: this.data.order.id,
      type: receivingStatusValue,
      is_true: examineValue,
      remark
    }
    wx.showLoading({
      title: '正在提交...',
    })
    const url = app.getNetAddresss(btn.api)
    app._postNetWork({
      url,
      data: params,
      success: function(res) {
        const resData = res.data
        if (resData.result == 1) {
          wx.showModal({
            title: '成功',
            content: resData.msg,
            showCancel: false,
            complete: (res) => {
              if (res.confirm) {
                wx.navigateTo({
                  url: '/pages/regimental-commander/order/order?orderType=waitRefund',
                })
              }
            }
          })
        } else {
          wx.showToast({
            icon: 'none',
            title: resData.msg,
          })
        }
      },
      complete: function() {
        wx.hideLoading()
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const params = JSON.parse(decodeURIComponent(options.params))
    this.setData({
      order: params.order,
      receivingStatusName: params.receivingStatus.name,
      receivingStatusValue: params.receivingStatus.value,
      btn: params.btn
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})